#include<bits/stdc++.h>
#define lowbit(i) i&(-i)
#define work \
for(int i=1;i<=4;i++)\
{\
    puts("fuck u zyq");\
}
using namespace std;
long long ans[200005],ans_[200005];
long long a[50005],c[200005];
long long SuM(long long x) {
	long long sum=0;
	for(int i=x-1; i>0; i-=lowbit(i)) sum+=c[i];
	return sum;
}
long long ctjer(long long x) {
	for(long long i=x; i<=200000; i+=lowbit(i)) c[i]++;
	return x;
}
inline long long read(){
	long long a=0;
	char ch;
	while((ch=getchar())!=' '&&ch!='\n'){
		a*=10;
		a+=ch-'0';
	}
	return a;
}
int main(int argc,char ** argv) {
	long long n=read(),_ans=0;
	for(int i=1; i<=n; i++) a[i]=read();
	memset(c,0,sizeof(c));
	for(int i=1; i<=n; i++) {
		ans[i]=SuM(ctjer(a[i]));
	}
	memset(c,0,sizeof(c));
	for(int i=n; i>=1; i--) {
		ans_[i]=SuM(ctjer(a[i]));
	}
	for(int i=1; i<=n; i++){
		_ans+=((n-(i+ans_[i]))
            * ans [i]+(i-(ans[i]+1))
            * ans_[i]);
	}
	printf("%lld\n",_ans);
    if(argc==2){} //work work work;
}